package com.zhengsr.latte.ui.recycler.adapter;

import android.view.ViewGroup;

import com.zhengsr.latte.ui.recycler.adapter.base.RBaseAdapter;
import com.zhengsr.latte.ui.recycler.adapter.base.RBaseViewholder;

import java.util.List;

public abstract class RNormalAdapter<T> extends RBaseAdapter {
    private static final String TAG = "RNormalAdapter";
    private int mLayoutId;
    private List<T> mDatas; //取泛型是因为不知道bean是啥类型的。
    public RNormalAdapter(int layoutid, List<T> list) {
        mLayoutId = layoutid;
        mDatas = list;
    }




    @Override
    public RBaseViewholder onCreateViewHolder(ViewGroup parent, int viewType) {
        RBaseViewholder viewholder = RBaseViewholder.getViewHolder(parent.getContext(),
                mLayoutId,parent);
        //放在这里，避免重复调用实例
        bindClickListener(viewholder,RNormalAdapter.this);
        return viewholder;
    }

    @Override
    public void onBindViewHolder(RBaseViewholder holder, int position) {
        getConver(holder,mDatas.get(position)); //提供 viewholder 出去，数据由用户处理
    }

    public abstract void getConver(RBaseViewholder holder,T data);


    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }


}